package com.tangbao.util;

import java.util.List;

/**
 * 创建人:zhouxin
 * 创建时间:2017/12/6
 * 功能:
 */
public class Page<T> {
    private Integer pageSize = 5;//每页5条
    private Integer totalCount = 0;//数据总量
    private Integer currentPage = 1;//当前页数
    private String orderby = "";
    private List<T> list;

    public Page(){}
    public Page(Integer pageSize, Integer currentPage) {
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.orderby = orderby;
    }
    public Page(Integer pageSize, Integer currentPage, String orderby) {
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.orderby = orderby;
    }

    /**
     * 获取分页起始位置
     * @return
     */
    public int getStart() {
        int start = (currentPage - 1)*pageSize;
        if(start<0) {
            return 0;
        }
        return start;
    }

    /**
     * 获取总共的页数
     * @return
     */
    public int getPageNum() {
        int page = totalCount/pageSize;
        if(totalCount%pageSize>0) {
            page++;
        }
        return page;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public String getOrderby() {
        return orderby;
    }

    public void setOrderby(String orderby) {
        this.orderby = orderby;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
